package com.bsoft.gol.hcs.specialist.dao;

import ctd.persistence.annotation.DAOMethod;
import ctd.persistence.annotation.DAOParam;
import ctd.persistence.support.hibernate.template.AbstractHibernateStatelessResultAction;
import ctd.persistence.support.hibernate.template.HibernateSessionTemplate;
import ctd.persistence.support.hibernate.template.HibernateStatelessResultAction;
import org.atag.dao.ext.HibernateExtendDAO;
import org.hibernate.Query;
import org.hibernate.StatelessSession;
import com.bsoft.gol.hcs.specialist.entity.FollowPatientLabelEntity;

import java.util.List;

/**
 * @author hekr22831
 * @description 患者标签
 * @date 2022/5/26.8:52
 */
public abstract class FollowPatientLabelDAO extends HibernateExtendDAO<FollowPatientLabelEntity> {

    /**
     * 查询患者标签
     * @param fusPathRouteId 院后随访id
     * @return
     */
    @DAOMethod(sql = "from FollowPatientLabel where fusPathRouteId=:fusPathRouteId ")
    public abstract List<FollowPatientLabelEntity> findFplByFusPathRouteId(@DAOParam("fusPathRouteId") long fusPathRouteId);

    @DAOMethod(sql = "from FollowPatientLabel where source=:source and visitNo=:visitNo ")
    public abstract List<FollowPatientLabelEntity> findFplByVisitNo(@DAOParam("source") Integer source,@DAOParam("visitNo") String visitNo);


    /**
     * 根据院后随访id 删除患者标签
     * @param fusPathRouteId
     */
    @DAOMethod(sql = "delete from FollowPatientLabel where fusPathRouteId=:fusPathRouteId")
    public abstract void deleteFollowPatientLabelById(@DAOParam("fusPathRouteId") long fusPathRouteId);

    public void insert(FollowPatientLabelEntity fpl) {
        HibernateStatelessResultAction<Void> action = new AbstractHibernateStatelessResultAction<Void>() {
            @Override
            public void execute(StatelessSession statelessSession) {
                String sql ="INSERT INTO follow_patient_label(fus_path_route_id,dispute_type) VALUES(:fusPathRouteId,:disputeType);";
                Query query = statelessSession.createSQLQuery(sql);
//                query.setParameter("patientId", fpl.getPatientId());
                query.setParameter("fusPathRouteId", fpl.getFusPathRouteId());
                query.setParameter("disputeType", fpl.getDisputeType());
                query.executeUpdate();
            }
        };
        HibernateSessionTemplate.instance().execute(action);
    }

}
